<template>
  <div class="container">
    <h3 class="title">
      <svg-icon icon-class="nested" class="title-icon" />订单管理
    </h3>

    <el-card>
      <div slot="header">
        <span>关联销售单</span>
      </div>
      <el-table
        :data="list"
        height="calc(100vh - 410px)"
        border
        stripe
        style="width: 100%;margin-bottom:10px;"
      >
        <el-table-column prop="id" label="序号"></el-table-column>
        <el-table-column prop="no" label="订单编号"></el-table-column>
        <el-table-column prop="userName" label="客户姓名"></el-table-column>
        <el-table-column prop="userPhone" label="手机号"></el-table-column>
        <el-table-column prop="userIdCard" label="身份证"></el-table-column>

        <el-table-column prop="projectName" label="项目"></el-table-column>
        <el-table-column label="房号">
          <template slot-scope="scope">{{scope.row.loudong}}栋{{scope.row.roomNo}}号</template>
        </el-table-column>
        <el-table-column prop="moneyType" label="款项类型"></el-table-column>
        <el-table-column prop="actualAmountReceived" label="实收金额"></el-table-column>
        <el-table-column prop="amountReceived" label="应收金额"></el-table-column>
        <el-table-colimn label="操作">
          <template slot-scope="scope">
            <el-button type="primary" @click="setContact(scope.row.no)">关联</el-button>
          </template>
        </el-table-colimn>
      </el-table>
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="page"
        :page-sizes="[10, 20, 30, 40]"
        :page-size="pageSize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="totalPage"
        style="float: right;"
      ></el-pagination>
      <div class="btn-group">
        <el-button type="primary" @click="setContact">关联</el-button>
      </div>
    </el-card>
  </div>
</template>

<script>
import { getContact, setContact } from "@/api/order";
export default {
  name: "contact",
  data() {
    return {
      list: [],
      id: "",
      pageSize: 10,
      page: 1,
      totalPage: 0,
      row: []
    };
  },
  mounted() {
    this.id = this.$route.query.id;
    this.getList();
  },
  methods: {
    setContact(no) {
      this.$confirm("您确定要关联吗?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      })
        .then(() => {
          setContact(this.id, no).then(res => {
            if (res.code == 200) {
              this.$message({
                type: "success",
                message: "关联成功"
              });
              window.location.reload();
            } else {
              this.$message(res.message);
            }
          });
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消关联"
          });
        });
    },
    getList() {
      getContact(this.page, this.pageSize).then(res => {
        this.list = res.data;
        this.totalPage = res.recordsTotal;
      });
    },
    handleSizeChange(val) {
      this.pageSize = val;
      this.getList();
    },
    handleCurrentChange(val) {
      this.page = val;
      this.getList();
    }
  }
};
</script>

<style lang="scss" scoped>
.container {
  padding: 20px;
  background-color: rgb(240, 242, 245);
  position: relative;
  .title {
    font-size: 14px;
    font-weight: 400;
    .title-icon {
      font-size: 14px;
      display: inline-block;
      margin-right: 5px;
    }
  }
  /deep/ .el-card__header {
    border: 0 none;
  }
}
.title-small {
  font-size: 14px;
}

.money {
  color: #409eff;
}
</style>
